<?php
class Event {
	private static $eventList = array();
	private static $eventListPage = array();
	public static function runEvent($eventName){
		if (DEV_MODE) {
			self::$eventListPage[] = $eventName;
		}
		
		if (isset(self::$eventList[$eventName])){
			foreach (self::$eventList[$eventName] as $v => $callback) {
				call_user_func_array($callback[0],$callback[1]);
			}
		}
	}
	public static function setEventHandler($eventName,$handler, array $params = array()){
		self::$eventList[$eventName][callback_to_string($handler)] = array($handler,$params);
	}
	public static function deleteEventHandler($eventName,$handler){
		unset(self::$eventList[$eventName][callback_to_string($handler)]);
	}
	public static function getEventsOnPage(){
		if (!DEV_MODE) return;
		Event::setEventHandler('end',array(__CLASS__,'_traceEvents'));
	}
	public static function _traceEvents(){
		debug(self::$eventListPage);
	}
}